package com.example.demo.service;

import com.example.demo.mapper.BlogInfoMapper;
import com.example.demo.mapper.UserInfoMapper;
import com.example.demo.model.BlogInfo;
import com.example.demo.model.UserInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class UserInfoService {



   @Autowired
   private BlogInfoMapper blogInfoMapper;
   @Autowired
    private UserInfoMapper userInfoMapper;


    public UserInfo selectByName(String userName){
        UserInfo userInfo = userInfoMapper.queryByName(userName);
        return userInfo;
    }

    public UserInfo selectById(Integer id){
        UserInfo userInfo = userInfoMapper.queryByID(id);
        return userInfo;
    }
    public UserInfo getAuthorInfo(Integer blogId) {
        //1. 根据博客ID, 获取作者ID
        //2. 根据作者ID, 获取作者信息
        BlogInfo blogInfo = blogInfoMapper.selectById(blogId);
        if (blogInfo==null && blogInfo.getUserId()<=0){
            log.error("博客不存在或作者信息不合法, blogId:{}", blogId);
            return null;
        }
        return userInfoMapper.selectById(blogInfo.getUserId());


    }
}
